#include <iostream>
#include "AbsThreads.h"

AbsThreads::AbsThreads(void)
{
	this->_ThreadId = NULL;
}

AbsThreads::~AbsThreads(void)
{
	CloseHandle(this->_ThreadId);
}

bool    AbsThreads::AbsCreateThread(void* routine, void* parameters)
{
	if (this->_ThreadId == NULL)
		this->_ThreadId = CreateThread(NULL, 0, static_cast<LPTHREAD_START_ROUTINE>(routine), parameters, 0, NULL);
	if (this->_ThreadId == NULL)
	{
		return (false);
	}
	return true;
}

void    AbsThreads::AbsJoinThread()
{
	if (this->_ThreadId != NULL)
	{
		WaitForSingleObject(this->_ThreadId, INFINITE);
	}
}

void    AbsThreads::AbsKillThread()
{
	if (this->_ThreadId != NULL)
	{
		std::cout << "ExitCode: " << TerminateThread(this->_ThreadId, 0) << std::endl;
		CloseHandle(this->_ThreadId);
		this->_ThreadId = NULL;
	}
}
